package com.csj.DesignPattern.iterator;

import java.util.List;

public class StudentIterator implements ObjectIterator<Student>{

    private List<Student> list;

    private int index = 0;

    public StudentIterator(List<Student> list) {
        this.list = list;
    }
    @Override
    public boolean hasNext() {
        return index < list.size();
    }

    @Override
    public Student next() {
        Student student = list.get(index);
        index++;
        return student;
    }
}
/*

public class ArrayList<E> {

    public Iterator<E> iterator() {
        return new Itr();
    }

    //同StudentIterator，继承了ObjectIterator接口
     private class Itr implements Iterator<E> {

        //重写了hasNext()方法
        public boolean hasNext() {
            return cursor != size;
        }
        //重写了next()方法
        public E next() {
            checkForComodification();
            int i = cursor;
            if (i >= size)
                throw new NoSuchElementException();
            Object[] elementData = ArrayList.this.elementData;
            if (i >= elementData.length)
                throw new ConcurrentModificationException();
            cursor = i + 1;
            return (E) elementData[lastRet = i];
        }
     }
}


 */
